package com.huiztech.kaoqinji;

import com.huiztech.kaoqinji.model.UserInfoDetail;
import com.lidroid.xutils.util.LogUtils;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends BaseActivity implements OnClickListener {

    private EditText usernameEdit, passwordEdit;
    private Button loginBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LogUtils.i("LoginActivity++++onCreate");
        UserInfoDetail userInfoDetail = controller.getUserFromLocal();
        if (userInfoDetail.getUsername() != null) {
            startActivity(new Intent(this, MainTabActivity.class));
            finish();
        } else {
            setContentView(R.layout.activity_login);
            findView();
            loginBtn.setOnClickListener(this);
        }

    }

    // UI初始化
    private void findView() {
        usernameEdit = (EditText) findViewById(R.id.login_username_edit);
        passwordEdit = (EditText) findViewById(R.id.login_password_edit);
        loginBtn = (Button) findViewById(R.id.login_submit_btn);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.login_submit_btn:
            if (!usernameEdit.getText().toString().trim().equals("")
                    && !passwordEdit.getText().toString().trim().equals("")) {
                controller.doLogin(usernameEdit.getText().toString(), passwordEdit.getText().toString());
            } else {
                view.showMessage("用户    名和密码不能为空！");
            }
            break;

        default:
            break;
        }
    }
}
